package com.itheima.ydd.controller;

import com.itheima.ydd.common.ResultData;

import com.itheima.ydd.entity.SysUserInfo;
import com.itheima.ydd.service.ISysRoleService;
import com.itheima.ydd.service.ISysUserService;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.DigestUtils;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * <p>
 * 用户表 前端控制器
 * </p>
 *
 * @author author
 * @since 2022-05-22
 */
@RestController
@RequestMapping("/sys_user")
@Slf4j
@CrossOrigin
public class SysUserController {
    @Autowired
    private ISysUserService userService;
    @Autowired
    private ISysRoleService roleService;
    /**
     * 分页查询
     * @param login_name
     * @param status
     * @param phone
     * @param page
     * @param limit
     * @return
     */
    @GetMapping("/list")
public ResultData getList(@RequestParam String login_name, @RequestParam String status, @RequestParam String phone, @RequestParam Integer page, @RequestParam Integer limit){
    return userService.getList(login_name,status, phone,  page,  limit);
}

    /**
     * 删除
     * @param id
     * @return
     */
    @GetMapping("/del")
    public ResultData deleteById(@RequestParam String id){
        return userService.deleteById(id);
    }

    /**
     * 查看详情
     * @param id
     * @return
     */
    @GetMapping("/rowInfo")
    public ResultData getDetail(@RequestParam String id){

        ResultData detail = userService.getDetail(id);
        return detail;
    }

    /**
     * 新增
     * @param sysUserInfo
     * @return
     */
    @PostMapping("add")
    public ResultData add(@RequestBody SysUserInfo sysUserInfo){
        return userService.add(sysUserInfo);
    }
    @PostMapping("/update")
    public ResultData update(@RequestBody SysUserInfo sysUserInfo){
        return userService.update(sysUserInfo);
    }
}
